let fun = {
    //读卡充值
    dukachongzhi(){
        let btn = {
            btn: ['确定', '取消']
            , yes:async function (index, layero) {
                //按钮【按钮一】的回调
                let win = getTopIframe(layero);
                let issubmit = win.verification();
                if (!issubmit) {
                    return false;
                }
                let data = win.getData();

                //上次是否刷卡标志
                let shangci_shuaka = true;
                let userCode = "";
                let i = top.load();
                //获取读卡的调用所有接口
                const res = await postWebCustom(getTableId("947"),{formdata:JSON.stringify(data)});
                if(res.code == 0){
                    top.layer.close(i);
                    top.alert(res.msg);
                    return ;
                }
                let listurl = res.data.list;
                if(listurl.length == 2){//如果要调用两个读卡接口
                    console.log(listurl[0]["dyjk"])
                    const reslocal = await postBodyNotHeaders(listurl[0]["dyjk"],{});
                    const parsres = await postWebCustom(getTableId("908"),{mapset:JSON.stringify(listurl[0]),res:JSON.stringify(reslocal)});
                    if(parsres.code == 0){
                        top.layer.close(i);
                        top.alert(parsres.msg);
                        return ;
                    }
                    const reslocal1 = await postBodyNotHeaders(parsres.data["dyjk"],JSON.parse(parsres.data["parms"]));
                    const parsres1 = await postWebCustom(getTableId("908"),{mapset:JSON.stringify(parsres.data),res:JSON.stringify(reslocal1)});
                    top.data.parsres1 = parsres1;
                    if(parsres1.code == 0){
                        top.layer.close(i);
                        top.alert(parsres1.msg);
                        return ;
                    }

                    try {
                        if(reslocal1.result == 1 && reslocal1.meters[0].zhuangtai ==0){
                            shangci_shuaka = true;
                        }else {
                            shangci_shuaka = false;
                        }
                    }catch (e){}

                    userCode = parsres1.data.userCode;

                }else {
                    console.log(listurl[0]["dyjk"]);
                    const reslocal = await postBodyNotHeaders(listurl[0]["dyjk"],JSON.parse(listurl[0]["parms"]));
                    const parsres = await postWebCustom(getTableId("908"),{mapset:JSON.stringify(listurl[0]),res:JSON.stringify(reslocal)});
                    top.data.parsres1 = parsres;
                    if(parsres.code == 0){
                        top.layer.close(i);
                        top.alert(parsres.msg);
                        return ;
                    }

                    if(listurl[0]["dkyz"] != undefined && listurl[0]["dkyz"] != ""){
                        if(!eval(listurl[0]["dkyz"])){
                            top.layer.close(i);
                            top.alert("水卡上次未刷表，请刷表后再购水！");
                            shangci_shuaka = false;
                            // return ;
                        }
                    }

                    userCode = parsres.data.userCode;
                }

                //查询相关的客户信息
                let rightuserCode = userCode;
                if(rightuserCode.indexOf("-")!=-1){
                    rightuserCode = rightuserCode.split("-")[1];
                }
                vm.searchInputDtos["user_code"].values = [rightuserCode];
                vm.searchInputDtos["user_code"].type = "6";
                vm.searchInputDtos["kplx"].values = [Object.values(data)[0]["kplx"]];
                vm.getListdata();

                vm.searchInputDtos["user_code"].type = "0";
                vm.searchInputDtos["user_code"].value = rightuserCode;


                //开始充值
                fun.chongzhi(userCode,data,shangci_shuaka);
            }
            , btn2: function (index, layero) {
                //按钮【按钮二】的回调
                //return false 开启该代码可禁止点击该按钮关闭
            }
        };
        top.f_layer_open_get("/admin/html/inputCustom/index.html?tableId="+getTableId("900"), "40%", "45%", function () {

        }, btn, "选择卡片",{});
    },
    //开始充值
    async chongzhi(userCode,fromdata,shangci_shuaka){
        let select_kid = Object.values(fromdata)[0]["kplx"];

        let i = top.load();
        //查詢客戶信息
        const getresdata = await postWebCustom(getTableId("902"),{user_code:userCode,select_kid:""+select_kid});
        top.layer.close(i);
        if(getresdata.code == 0){
            top.alert(getresdata.msg);
            return;
        }
        top.layer.closeAll();

        let btn = {
            btn: ['确定', '取消']
            , yes:async function (index, layero) {
                //按钮【按钮一】的回调
                let win = getTopIframe(layero);
                let issubmit = win.verification();
                if (!issubmit) {
                    return false;
                }

                let data = win.getData();
                let i = top.load();
                //获取本地调用购买接口地址
                let khid = Object.values(data)[0]["id"];
                let gml = Object.values(data)[1]["gml"];

                let r962 = await listAdmin(getTableId("962"),"id",{"khid":khid});
                let rlistda = r962.data;
                if(!shangci_shuaka && rlistda.length == 0){
                    top.alert("水卡上次未刷表，请刷表后再购水！");
                    return ;
                }
                if(shangci_shuaka && rlistda.length>0){
                    //如果已经刷表了，则要把退款剩余金额删除
                    await deleteData(getTableId("962"),rlistda[0].id,{});
                }

                const reslocal = await postWebCustom(getTableId("907"),{"khid":""+khid,bugvalue:""+gml,fromdata:JSON.stringify(data)});
                if(reslocal.code == 0){
                    top.layer.close(i);
                    top.alert(reslocal.msg);
                    return ;
                }

                //开始调用本地读写卡服务
                let localurl = reslocal.data["dyjk"];
                let pdata = JSON.parse(reslocal.data["parms"]);
                const res = await postBodyNotHeaders(localurl,pdata);
                const parsres = await postWebCustom(getTableId("908"),{mapset:JSON.stringify(reslocal.data),res:JSON.stringify(res)});
                if(parsres.code == 0){
                    top.layer.close(i);
                    top.alert(parsres.msg);
                    return ;
                }

                //卡片充值成功后保存数据到数据库
                const czres = await postWebCustom(getTableId("905"),{jsontext:JSON.stringify(data)});
                if(czres.code == 0){
                    top.layer.close(i);
                    top.alert(czres.msg);
                    return;
                }
                top.layer.closeAll();
                top.alert(czres.msg);
            }
            , btn2: function (index, layero) {
                //按钮【按钮二】的回调
                //return false 开启该代码可禁止点击该按钮关闭
            }
        };

        top.f_layer_open_get("/admin/html/module/shuiwu/kehu/jiaofeiInput.html?tableId="+getTableId("901")+"&shangci_shuaka="+shangci_shuaka, "80%", "80%", function () {

        }, btn, "客户充值",getresdata.data);
    }
}